<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars3d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>数字城市 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>

    <!--第三方lib-->
    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,bootstrap,bootstrap-slider,layer,haoutil,turf,mars3d"
    ></script>

    <link href="css/style.css" rel="stylesheet" />
    <style type="text/css">
      /**一个简单文本DIV面板**/
      .marsBlackPanel {
        min-width: 90px;
        min-height: 35px;
        position: absolute;
        left: 16px;
        bottom: 31px;
        cursor: default;
        opacity: 0.96;
        box-sizing: border-box;
      }

      .marsBlackPanel::before {
        content: "";
        width: calc(100% + 22px);
        height: 39px;
        position: absolute;
        bottom: -39px;
        left: -22px;
        background: url(../example/img/marker/popupLbl.png) 0px 0px no-repeat;
        background-position: 0px 0px;
        background-size: cover;
      }

      .marsBlackPanel-text {
        width: 100%;
        height: 100%;
        text-align: center;
        padding: 1px 20px;
        font-size: 23px;
        font-family: "MicrosoftYaHei";
        font-weight: 100;
        color: yellow;
        line-height: 33px;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        white-space: nowrap;
      }
    </style>
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <script src="./js/common.js"></script>
    <script type="text/javascript">
      "use script"; //开发环境建议开启严格模式

      var map;

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          scene: {
            center: { lat: 31.253607, lng: 121.519759, alt: 1492, heading: 203, pitch: -33 },
          },
          layers: [
            {
              type: "3dtiles",
              name: "上海市建筑物",
              url: "//data.mars3d.cn/3dtiles/jzw-shanghai/tileset.json",
              maximumScreenSpaceError: 1,
              maximumMemoryUsage: 1024,
              style: {
                color: "rgb(0, 99, 255)",
              },
              marsJzwStyle: true,
              popup: [
                { field: "objectid", name: "编号" },
                { field: "name", name: "名称" },
                { field: "height", name: "楼高", unit: "米" },
              ],
              show: true,
            },
            {
              type: "geojson",
              name: "市区一级道路",
              url: "//data.mars3d.cn/file/geojson/shanghai-road.json",
              symbol: {
                styleOptions: {
                  width: 2.0,
                  material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ODLine, {
                    bgColor: new Cesium.Color(0.1, 0.7, 0.5, 0.4),
                    color: new Cesium.Color(Math.random() * 0.5 + 0.5, Math.random() * 0.8 + 0.2, 0.0, 1.0),
                    speed: 20 + 1.0 * Math.random(),
                    startTime: Math.random(),
                  }),
                },
              },
              popup: "{Name}",
              show: true,
            },
          ],
        });
        // delete mapOptions.control;

        //创建三维地球场景
        map = new mars3d.Map("mars3dContainer", mapOptions);
        map.basemap = 2017; //切换到蓝色底图

        // 3d模型裁剪
        var tilesetPlanClip = new mars3d.thing.TilesetPlanClip({
          layer: map.getLayer("上海市建筑物", "name"),
          clipOutSide: true,
          positions: [
            [121.477666, 31.217061, 19.1],
            [121.531567, 31.217061, 19.1],
            [121.531567, 31.258551, 19.1],
            [121.477666, 31.258551, 19.1],
          ],
        });
        map.addThing(tilesetPlanClip);

        //特效
        var bloomEffect = new mars3d.effect.BloomEffect({
          enabled: true,
        });
        map.addEffect(bloomEffect);

        // 围绕旋转
        let rotatePoint = new mars3d.thing.RotatePoint({
          direction: true, //方向 true逆时针，false顺时针
          time: 50, //给定飞行一周所需时间(单位 秒)，控制速度
        });
        map.addThing(rotatePoint);
        // rotatePoint.start();

        //添加矢量数据
        addCityGraphics();
      }

      function addCityGraphics() {
        //创建Graphic图层
        var graphicLayer = new mars3d.layer.GraphicLayer();
        map.addLayer(graphicLayer);

        // 模型的中心点
        var position = [121.510608, 31.234322, 0]; // 用于围绕旋转 + 中心点扩散 + 旋转的图片
        var center = Cesium.Cartesian3.fromDegrees(position[0], position[1], 140); // 用于div标注和远眺的线

        // 中心扩散点
        var circleDiffuseWallGlow = new mars3d.graphic.DiffuseWall({
          name: "中心扩散点",
          position: position,
          style: {
            diffHeight: 500, //高度
            radius: 150, //半径
            color: "#7ffeff",
            speed: 6, //速度
          },
        });
        graphicLayer.addGraphic(circleDiffuseWallGlow);

        // 旋转的图片 -- 中心围墙
        var WallImagePositions = mars3d.PolyUtil.getEllipseOuterPositions({
          position: position,
          radius: 50, //半径
          count: 50, //共返回(count*4)个点
        });
        var rotatWallImage = new mars3d.graphic.WallPrimitive({
          positions: WallImagePositions,
          style: {
            diffHeight: 190,
            closure: true,
            material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.RectSlide, {
              image: "img/tietu/circular.png",
              speed: 2,
            }),
          },
        });
        graphicLayer.addGraphic(rotatWallImage);

        // 旋转的图片 -- 底部
        var rotation = Cesium.Math.toRadians(50);
        function getRotationValue() {
          rotation -= 0.007;
          return rotation;
        }
        var rotatCicleImage = new mars3d.graphic.CircleEntity({
          position: position,
          style: {
            radius: 500,
            height: 50,
            material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.Image2, {
              image: "../example/img/textures/circle_bg.png",
            }),
            rotation: new Cesium.CallbackProperty(getRotationValue, false),
            stRotation: new Cesium.CallbackProperty(getRotationValue, false),
          },
        });
        graphicLayer.addGraphic(rotatCicleImage);

        //
        var graphic = new mars3d.graphic.ModelEntity({
          name: "四凌锥体",
          position: [position[0], position[1], 180],
          style: {
            url: "//data.mars3d.cn/gltf/mars/zhui.glb",
            scale: 30,
          },
        });
        graphicLayer.addGraphic(graphic);

        //开始 自旋转效果
        graphic.rotateStart({
          direction: true, //控制方向, true逆时针，false顺时针
          time: 6, //time：给定飞行一周所需时间(单位 秒)，控制速度
        });

        // divgraphic标注
        var divgraphic = new mars3d.graphic.DivGraphic({
          position: center,
          style: {
            html: `<div class="marsBlackPanel">
                <div class="marsBlackPanel-text">Mars3D国际大厦</div>
            </div>`,
            horizontalOrigin: Cesium.HorizontalOrigin.LEFT, //横向定位
            verticalOrigin: Cesium.VerticalOrigin.CENTER, //垂直定位
          },
        });
        graphicLayer.addGraphic(divgraphic);

        // 扫描圆形
        var scanCircle = new mars3d.graphic.CircleEntity({
          position: Cesium.Cartesian3.fromDegrees(121.501618, 31.235704, 24.2),
          style: {
            radius: 480.0,
            material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.CircleScan, {
              image: "../example/img/textures/circleScan.png",
              color: "#ffffff",
            }),
            stRotation: new Cesium.CallbackProperty(getRotationValue, false),
            classificationType: Cesium.ClassificationType.BOTH,
            clampToGround: true,
          },
        });
        graphicLayer.addGraphic(scanCircle);

        // 远眺的线 ,数据获取的pointArr
        queryAreasData().then((res) => {
          var lineMaterial = mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ODLine, {
            color: new Cesium.Color(1, 1, 1),
            bgColor: new Cesium.Color(0.1, 0.7, 0.5, 0.4),
            speed: 5 + 1.0 * Math.random(),
            startTime: Math.random(),
          });

          for (var i = 0, len = res.length; i < len; i++) {
            let item = res[i];

            let color = ["#ffff00", "#81d8ff", "#fff9ed"];
            let thisPoint = Cesium.Cartesian3.fromDegrees(item.point[0], item.point[1], 1);
            let positions = mars3d.PolyUtil.getLinkedPointList(center, thisPoint, 40000, 100); //计算曲线点

            var primitive = new mars3d.graphic.PolylinePrimitive({
              positions: positions,
              style: {
                width: 4,
                material: lineMaterial, //动画线材质
              },
            });
            primitive.bindPopup(item.name);
            graphicLayer.addGraphic(primitive);

            // 圆椎体
            var coneGlow = new mars3d.graphic.LightCone({
              position: Cesium.Cartesian3.fromDegrees(item.point[0], item.point[1], 10),
              style: {
                radius: 10,
                height: 200,
                color: color[i % color.length],
              },
              popup: item.name,
            });
            graphicLayer.addGraphic(coneGlow);
          }
        });

        //竖直飞线
        var arrData = [];
        for (var j = 0; j < 100; ++j) {
          var startPt = randomPoint();

          let endPt = startPt.clone();
          endPt.alt = haoutil.math.random(600, 1000);

          let startTime = haoutil.math.random(0, 10000);
          let speed = haoutil.math.random(1, 35);

          arrData.push({
            positions: [startPt, endPt],
            style: {
              width: 1,
              material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ODLine, {
                color: "rgb(255, 255, 2)",
                bgColor: "rgb(0,0,0,0.1)",
                startTime: startTime,
                speed: speed,
              }),
            },
          });
        }
        var upPoly = new mars3d.graphic.PolylineCombine({
          instances: arrData,
        });
        graphicLayer.addGraphic(upPoly);
      }

      //数据获取 返回pointArr
      function queryAreasData() {
        return new Promise(function (resolve, reject) {
          $.ajax({
            url: "//data.mars3d.cn/file/geojson/shanghai-point.json",
            type: "get",
            dataType: "json",
            success: function (result) {
              let pointArr = [];
              result.features.forEach((obj) => {
                pointArr.push({
                  name: obj.properties.Name,
                  point: obj.geometry.coordinates,
                });
              });
              resolve(pointArr);
            },
            error: function (data) {
              reject(data);
            },
          });
        });
      }

      //取区域内的随机图标；用于线对象的合并渲染
      function randomPoint() {
        var jd = haoutil.math.random(121.500525 * 1000, 121.518298 * 1000) / 1000;
        var wd = haoutil.math.random(31.231515 * 1000, 31.24228 * 1000) / 1000;
        return new mars3d.LatLngPoint(jd, wd, 50);
      }
    </script>
  </body>
</html>
